//
//  ListSecondDetailsViewController.m
//  项目A --半糖
//
//  Created by romana on 16/5/25.
//  Copyright © 2016年 romana. All rights reserved.
//

#import "ListSecondDetailsViewController.h"
#import "AFNetworking.h"
#import "ListDetailsVCModel.h"
#import "ListDetailsTableViewCell.h"
#import "ListThirdDetailsViewController.h"


#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface ListSecondDetailsViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)NSMutableArray *myArray;
@property(nonatomic,strong)UITableView *myTableView;

@end

@implementation ListSecondDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
   // NSLog(@"self.LVCModel.modelId ======%@",self.LVCModel.modelId);
  
    self.view.backgroundColor = [UIColor purpleColor];
   //设置导航栏标题
    self.navigationItem.title = self.LVCModel.name;
   // NSLog(@"%@",self.LVCModel.modelId);
    self.myArray = [NSMutableArray array];
    [self getData];
    
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0 , WIDTH, HEIGHT - 49) style:UITableViewStylePlain];
    self.myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTableView];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
    [self.myTableView registerClass:[ListDetailsTableViewCell class] forCellReuseIdentifier:@"reuse"];
    
    
    
    
    
    // Do any additional setup after loading the view.
}

-(void)getData{

    NSString *string1 = @"iPhone7%2C1";
    NSString *string = [NSString stringWithFormat:@"http://open3.bantangapp.com/search/topic/listByScene?app_id=com.jzyd.BanTang&app_installtime=1434705307&app_versions=5.8&channel_name=appStore&client_id=bt_app_ios&client_secret=9c1e6634ce1c5098e056628cd66a17a5&id=%@&oauth_token=8a11f2b3cd8fd625a8d8e9effb21dd0f&os_versions=9.3.2&page=0&pagesize=20&screensize=1242&sort_type=0&track_device_info=%@&track_deviceid=C2D3B460-4E0E-4639-A030-D274CFC43D50&track_user_id=125107&v=13",self.LVCModel.modelId,string1];
    
    
//    http://open3.bantangapp.com/search/topic/listByScene?app_id=com.jzyd.BanTang&app_installtime=1434705307&app_versions=5.8&channel_name=appStore&client_id=bt_app_ios&client_secret=9c1e6634ce1c5098e056628cd66a17a5&id=1&oauth_token=8a11f2b3cd8fd625a8d8e9effb21dd0f&os_versions=9.3.2&page=0&pagesize=20&screensize=1242&sort_type=0&track_device_info=iPhone7%2C1&track_deviceid=C2D3B460-4E0E-4639-A030-D274CFC43D50&track_user_id=125107&v=13
//    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:string parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSMutableDictionary *bigDic = responseObject;
        NSMutableArray *dataArray = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in dataArray) {
            ListDetailsVCModel *model = [[ListDetailsVCModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.myArray addObject:model];
        }
        [self.myTableView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];



}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return self.myArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    ListDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    cell.Model = [self.myArray objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    
 //   cell.textLabel.text = @"11111";
    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 290;

}

//点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ListThirdDetailsViewController *newSeDeVC = [[ListThirdDetailsViewController alloc] init];
    newSeDeVC.newseModel = [self.myArray objectAtIndex:indexPath.row];
    
    [self.navigationController pushViewController:newSeDeVC animated:YES];
    
    
}


@end
